package com.servlet;

import com.alibaba.fastjson.JSON;
import com.pojo.text;
import com.service.textService;
import com.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(value = "/text_SelectUser")
public class text_SelectUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        textService t = new textService();
        userService u = new userService();//xxx的个人空间

//         获取前端传过来的id，转化为int
        String uId = req.getParameter("uId");
        Integer id = Integer.valueOf(uId);


        //根据id查询text和userNAME
        String userName = u.user_selectName(id);
        List<text> texts = t.textselectUser(id);


        /**  本来此处想用纯html的，不过不会用
         * //转化为json格式
         *         String strings_json = JSON.toJSONString(strings);
         *
         *         //设置响应格式
         *         res.setContentType("text/json;Charset=utf-8");
         *         //后端发JSON串，前端then里的响应数据是json数组
         *         res.getWriter().write(strings_json);
         */

        req.setAttribute("Name",userName);
        req.setAttribute("T",texts);
        //请求转发
        req.getRequestDispatcher("/personal.jsp").forward(req,res);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
